package com.example.uniappspringbootstartweb.controller;

import com.example.uniappspringbootstartweb.entity.Shares;
import com.example.uniappspringbootstartweb.service.SharesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by lilijava
 * on 2024/12/31
 * <p>
 * on  uni-app-springboot-start-web
 * @author DELL
 */
@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/api/share")
public class SharesController {
    @Autowired
    private SharesService sharesService;
    @GetMapping("/total")
    public int getSharesByContentId(Integer contentId) {
       List<Shares> list=sharesService.getSharesByContentid(Long.valueOf(contentId));
        int size = list.size();
        return size;
    }
    @GetMapping("/add")
    public int save(Integer contentId) {
//        long a=(Long) session.getAttribute("userId");
        Shares share= new Shares(Long.valueOf(contentId), 1l);
        sharesService.save(share);
        List<Shares> list=sharesService.getSharesByContentid(Long.valueOf(contentId));
        int size = list.size();
        return size;
    }


}
